<template>
    <div>
        <script id="editor" type="text/plain" ></script>
    </div>
</template>

<script>
    import '../../public/ue/ueditor.config.js'
    import '../../public/ue/ueditor.all.js'
    import '../../public/ue/lang/zh-cn/zh-cn.js'

    export default {
        name: "editor",
        props: {
            id: {
                type: String
            },
            config: {
                type: Object
            },

            /**
             * 最后还是采用，路由传值，再传到组件里面进行初始化内容
             */
            defaultContent:{
                type: String
            }
        },
        data() {
            return {
                editor: null
            }
        },
        mounted() {
            //初始化UE
            const _this = this;
            this.editor = UE.getEditor('editor',this.config);
            this.editor.addListener("ready", function () {
                _this.editor.setContent(_this.defaultContent); // 确保UE加载完成后，放入内容。
            });
        },
        destoryed() {
            this.editor.destory();
        },
        methods:{
            // 获取内容
            getUEContent: function(){
                return this.editor.getContent();
            },
            setUEContent: function (text) {
                const _this = this;
                _this.editor.setContext(text);
            }
        }
    }
</script>
